package org.wangchaocheng.cloudgallery.user;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.wangchaocheng.cloudgallery.api.user.RoleServiceI;
import org.wangchaocheng.cloudgallery.commond.user.RoleSaveCmd;
import org.wangchaocheng.cloudgallery.dto.common.PageDTO;
import org.wangchaocheng.cloudgallery.dto.user.RoleDTO;
import org.wangchaocheng.cloudgallery.query.user.RolePageQry;
import org.wangchaocheng.cloudgallery.user.assembler.RoleAssembler;
import org.wangchaocheng.cloudgallery.user.gateway.RoleGateway;

/**
 * @author wangchaocheng
 * @date 2025/04/08
 */
@Service
@RequiredArgsConstructor
public class RoleServiceImpl implements RoleServiceI {

    private final RoleGateway roleGateway;

    @Override
    public void save(RoleSaveCmd cmd) {
        RoleDTO roleDTO = RoleAssembler.INSTANCE.assembleDTO(cmd);
        roleGateway.save(roleDTO);
    }

    @Override
    public RoleDTO findById(Long roleId) {
        return roleGateway.findByColumn(RoleDTO::getId, roleId);
    }

    @Override
    public PageDTO<RoleDTO> listPageRole(RolePageQry qry) {
        return roleGateway.listPage(qry);
    }
}
